<template>
<div class="content" v-if="dataShow">
  <idx_pop ref="idxPop" :maxMoney="dataShow.max_money" @shareOpen="dataShow" :qrCode="hlepInfo.qrcode" :helpid="hlepInfo?hlepInfo.help.helpid:''" :popPlay="dataShow.helpid==0" :ruleText="hlepInfo?hlepInfo.help.rule:''" @helpStart="this.dataShowFn"></idx_pop>
  <idx_header @openRulePop="$refs.idxPop.pop=4" @contactOpen="$refs.idxPop.pop=8"></idx_header>
  <idx_money :helpData="hlepInfo?hlepInfo:''" @openSharePop="$refs.idxPop.pop=5" @openRulePop="$refs.idxPop.ruleAgreeFn()"></idx_money>
  <idx_aid :helpData="hlepInfo?hlepInfo.user:''"></idx_aid>
</div>
</template>

<script>
export default{
  data(){
    return{
      dataShow:'',
      hlepInfo:''
    }
  },
  mounted(){
    this.dataShowFn();
  },
  methods:{
    dataShowFn(){
      this.api.getHomeDate().then(res=>{
        this.dataShow=res.data.data;
        if(this.$route.query.code){
          this.$nextTick(()=>{
            this.$refs.idxPop.pop=2;
          });
          return;
        }
        if(this.dataShow.helpid>0){
          this.helpDataFn({
            helpid:this.dataShow.helpid,
            url:window.location.href
          });
        }
      });
    },
    helpDataFn(data){
      this.api.helpGet(data).then(res=>{
        this.hlepInfo=res.data.data;
        let confits={
          debug:false,
          appId:res.data.data.share.appId,
          timestamp:res.data.data.share.timestamp,
          nonceStr: res.data.data.share.noncestr,
          signature: res.data.data.share.signature,
          jsApiList: [
            'checkJsApi',
            'openLocation',
            'getLocation',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'updateAppMessageShareData',
            'updateTimelineShareData'
          ]
        };
        this.wxSdk.config(confits);
        let option={
          title:res.data.data.share.share_title,        // 分享标题
          desc:res.data.data.share.share_desc,          // 分享描述
          link:res.data.data.share.share_url,           // 分享链接
          imgUrl:res.data.data.share.share_img,         // 分享图标
          success:function(){
            console.log('分享成功');
          },
          cancel:function(res){
            console.log(res);
          }
        };
        this.wxSdk.ready(()=>{
          this.wxSdk.onMenuShareAppMessage(option);
          this.wxSdk.onMenuShareTimeline(option);
          this.wxSdk.updateAppMessageShareData(option);
          this.wxSdk.updateTimelineShareData(option);
        });
      });
    }
  }
}
</script>

<style lang="scss" type="text/scss" scoped>
.content{
  background:url($imgUrl+'mainBg.jpg') #E1725A no-repeat center top;
  background-size:100% auto;
  padding-bottom:40px;
}
</style>
